package cn.szabadsag.hrm.controller;

import cn.szabadsag.hrm.dto.SmsCodeDTO;
import cn.szabadsag.hrm.service.IVerifycodeService;
import cn.szabadsag.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author yangcong
 * @date 2022年04月13日 15:58
 * @since
 */
@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {

    @Autowired
    private IVerifycodeService verifycodeService;

    /**
     * 手机短信验证码
     */
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody @Valid SmsCodeDTO dto){
        verifycodeService.sendSmsCode(dto);
        return AjaxResult.me();
    }

    /**
     * 图片验证码
     */
    @GetMapping("/imageCode/{key}")
    public AjaxResult createImageCode(@PathVariable("key") String key){
        //  返回一个Base64编码后的图片验证码
        String base64 = verifycodeService.createImageCode(key);
        return AjaxResult.me().setResultObj(base64);
    }
}
